<?php
/**
 * $Id: gallery_controller.php 177 2010-07-27 13:26:10Z varun $
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * This is parent of parent class of a controller and should not be edited ever without permission.
 * @version 			$Rev: 177 $
 * @lastModifiedBy		$LastChangedBy: varun $
 * @lastChanged			$Date: 2010-07-27 18:56:10 +0530 (Tue, 27 Jul 2010) $
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */

/**
 * Gallery controller. Will be useful when showing attractive display of an item's media.
 *
 */
class GalleryController extends AppController {

	var $name = 'Gallery';
	var $uses = array('Assets.Asset');
	var $helpers = array('Assets.Asset', 'Assets.Gallery','Html','Form','Cms.Restricted','Effects.Navigation');
	
	/**
	 * Simple gallery page
	 *
	 * @param unknown_type $type
	 * @param unknown_type $item_id
	 */
	function show($type, $item_id)
	{
		// set gallery title
		$title = $this->Asset->getItemTitle($type, $item_id);
		$this->pageTitle = $title." Gallery";
		$this->set('galleryTitle', $this->pageTitle);
		
		$this->set('galleryItems',$this->paginate(array('Asset.type'=>$type, 'Asset.item_id'=>$item_id)));
	}
	

	/**
	 * Gallery page with comments. Should be used through routes only.
	 *
	 * @param unknown_type $type
	 * @param unknown_type $item_id
	 */
	function showWithComments($type, $item_id)
	{
		$type = ucfirst($type);
		// set gallery title
		$title = $this->Asset->getItemTitle($type, $item_id);
		$this->pageTitle = $title." Gallery";
		$this->set('galleryTitle', $this->pageTitle);
		$galleryItems = $this->paginate(array('Asset.type'=>$type, 'Asset.item_id'=>$item_id));
		$galleryItems_new = array();
		foreach($galleryItems as $galleryItem)
		{
			$galleryItem['Asset']['commentCount'] = $this->Comment->findCount(array('Comment.type'=>'Asset', 'Comment.item_id'=>$galleryItem['Asset']['id']));
			$galleryItems_new[] = $galleryItem;
		}
		$this->set('itemInfo',$this->Asset->getItem($type, $item_id));
		$this->set('galleryItems',$galleryItems_new);		
	}
	
	/**
	 * Gallery page of a specific user.$type is for type column in assets table.If user_id is null users see his own profile
	 *
	 * @param unknown_type $type
	 * @param unknown_type $user_id
	 */
	function userGallery($type='all',$user_id=null)
	{
		$condition='';
		if(!$user_id)
		{
			if($this->Session->read('Auth.User.id'))
			{
				$user_id = $this->Session->read('Auth.User.id');
				$user['User'] = $this->Session->read('Auth.User');
			}
			else
			{
				$this->errorMsg(__('Please login to view this page'));
				$this->redirect($this->Auth->loginRedirect.'/redirectBack:true');
			}
			$this->pageTitle='My Gallery';
		}
		else
		{
			$user = $this->Asset->User->findById($user_id);
			$this->pageTitle = 'Gallery of '.$user['User']['name'];
		}
		if($type!='all')
		{
			$this->checkPluginAccess($type);
			$condition =' AND Asset.type="'.ucfirst($type).'"';
		}
		$this->paginate = array('recursive'=>0,'limit'=>8);
		$assets = $this->paginate(array('Asset.user_id = '.$user_id.$condition));
		$this->set('assetitems',$assets);
		$this->set('user',$user);
	}


}
?>